using System;
using DG.Tweening;
using Dream.Dialogue.Base;
using UnityEngine;

//mao 24-11-23 02:46
namespace Dream.Dialogue.Implement
{
    public class InteractTalk : TalkBase
    {
        //Text的最高父级别
        [SerializeField] private GameObject panel;

        //判断动画是否完成
        private Tweener _tweener;

        private event Action _callBack;


        public void SetTextCompleteCallBack(Action callback)
        {
            _callBack = callback;
        }

        public override void SetWord(string talkText)
        {
            words = talkText;
        }

        public override void Talk()
        {
            // text.transform.parent.gameObject.SetActive(true);
            panel.SetActive(true);
            text.text = "";
            _tweener?.Kill();
            _tweener = text.DOText(words, time).OnComplete(() => { _callBack?.Invoke(); });
        }

        public override bool StartTalk()
        {
            var isPlaying = _tweener?.IsPlaying() ?? false;
            if (!isPlaying)
                Talk();
            else
                text.DOComplete();
            return isPlaying;
        }
    }
}